package cn.jzq.kotoba.modules.designpattern.demo.demo1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class Test {

    public static void main(String[] args) {
        List<Node> nodeList = new ArrayList<>();
        nodeList.add(new Node(0, 1));
        nodeList.add(new Node(5, 6));
        nodeList.add(new Node(1, 3));
        nodeList.add(new Node(3, 5));

        List<Integer> idList = Arrays.asList(0, 1, 3, 5, 6);

//        Node n = nodeList.stream().filter(node -> Objects.equals(node.getId(), 1)).findFirst().orElse(null);
//        Node nextN = nodeList.stream().filter(node -> Objects.equals(node.getNextId(), n.getId())).findFirst().orElse(null);
        Integer nextId = 1;
        Node nextN = null;
        List<Integer> resultList = new ArrayList<>();
        resultList.add(0);
        resultList.add(1);
//        for (Integer id : idList) {
        for (int i = 0; i < idList.size() - 2; i++) {
            for (Node n : nodeList) {
                if (Objects.equals(n.getId(), nextId)) {
                    nextN = n;
                    break;
                }
            }
            if (nextN != null) {
                resultList.add(nextN.getNextId());
                nextId = nextN.getNextId();
            } else {
                break;
            }
        }
        System.out.println(resultList);
    }
}
